package com.smartguard.listener;

import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ConcurrentMap;
import java.util.concurrent.CopyOnWriteArrayList;

import javax.servlet.ServletContext;
import javax.servlet.ServletContextEvent;
import javax.servlet.ServletContextListener;

import com.smartguard.bean.Device;
import com.smartguard.common.Const;

public class ApplicationListener implements ServletContextListener {

	@Override
	public void contextDestroyed(ServletContextEvent arg0) {

	}

	@Override
	public void contextInitialized(ServletContextEvent arg0) {
		System.out.println("ApplicationListener inited.");
		
		ServletContext context = arg0.getServletContext();
		//生成一个数据结构用来保存当前在线的设备
		ConcurrentMap<String, CopyOnWriteArrayList<Device>> onlineDevice
		= new ConcurrentHashMap<String, CopyOnWriteArrayList<Device>>();
		
		context.setAttribute(Const.SESSION_USER_DEVICE, onlineDevice);
 
	}

}
